/**
 * Created by Administrator on 2017/3/8.
 */
/**
 * Created by Administrator on 2017/3/8.
 * 数据接口模块
 */
const express = require('express');

const router = express.Router();
// const User = require('../models/User.js');
const Content = require('../models/Content.js');

// 统一返回格式
const responseData = {
  code: 200,
  message: '成功',
};

router.get('/content/findList', (req, res, next) => {
  // 通过设置  加载body-parser，用来处理前端传过来的数据 有个body的属性
  Content.find().limit(10).sort({ _id: -1 }).then((contentList) => {
    res.json({
      data: contentList,
    });
  });
});

router.get('/content/:id', (req, res, next) => {
  const { id } = req.params;
  const condition = { _id: id };
  Content.findOne(condition).then((content) => {
    res.json({
      data: content,
    });
  });
});

module.exports = router;
